package com.chen.rabbitmq.six;

import com.chen.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

/**
 * @author Y·C
 * @version 1.0.0
 * @ClassName ReceiveLogsDirect01.java
 * @Description TODO
 * @createTime 2023年05月10日 15:50:00
 */
public class ReceiveLogsDirect01 {

    //交换机名称
    private static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();

        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个队列
        channel.queueDeclare("console",false,false,false,null);

        //队列的捆绑
        channel.queueBind("console",EXCHANGE_NAME,"info");
        channel.queueBind("console",EXCHANGE_NAME,"warning");

        channel.basicConsume("console", true,
                (consumerTag, message) -> System.out.println("ReceiveLogsDirect01 控制台打印接收到的消息" + new String(message.getBody(),"UTF-8")),
                consumerTag -> System.out.println(consumerTag + "消费者取消消费接口回调"));
    }
}
